import { Module } from '@nestjs/common';
import { UserModule } from './user/user.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { User } from './user/entities/user.entity';
import { AuthModule } from './auth/auth.module';
import { ConfigModule } from '@nestjs/config';
import { GoodsModule } from './goods/goods.module';
import { Goods } from './goods/entities/goods.entity';
import { CategoryModule } from './category/category.module';
import { Category } from './category/entities/category.entity';
import * as path from 'path';
import { diskStorage } from 'multer';
import { MulterModule } from '@nestjs/platform-express';
import { FileController } from './file/file.controller';
import { ActivePageModule } from './active-page/active-page.module';
import { ActivePage } from './active-page/entities/active-page.entity';
import { NoticeModule } from './notice/notice.module';
import { Notice } from './notice/entities/notice.entity';
import { Banner } from './banner/entities/banner.entity';
import { BannerModule } from './banner/banner.module';
import { CardModule } from './card/card.module';
import { Card } from './card/entities/card.entity';
import { Brand } from './brand/entities/brand.entity';
import { BrandModule } from './brand/brand.module';
import { Order } from './order/entities/order.entity';
import { OrderModule } from './order/order.module';
import { AddressModule } from './address/address.module';
import { Address } from './address/entities/address.entity';
@Module({
  imports: [
    UserModule,
    AuthModule,
    TypeOrmModule.forRoot({
      type: 'mysql',
      host: 'localhost',
      port: 3306,
      username: 'root',
      password: '123456',
      database: 'nestadmin',
      entities: [
        User,
        Goods,
        Category,
        ActivePage,
        Notice,
        Banner,
        Card,
        Brand,
        Order,
        Address,
      ],
      synchronize: true,
      logging: true,
      autoLoadEntities: true,
    }),
    ConfigModule.forRoot({
      envFilePath: '.env',
      ignoreEnvFile: false,
      isGlobal: true,
    }),
    GoodsModule,
    CategoryModule,
    // 文件上传
    MulterModule.register({
      storage: diskStorage({
        // 指定文件存储目录
        destination: path.join(__dirname, '../public/uploads'),
        // 通过时间戳来重命名上传的文件名
        filename: (_, file, callback) => {
          return callback(
            null,
            `${new Date().getTime() + path.extname(file.originalname)}`,
          );
        },
      }),
    }),
    ActivePageModule,
    NoticeModule,
    BannerModule,
    CardModule,
    BrandModule,
    OrderModule,
    AddressModule,
  ],
  controllers: [FileController],
  providers: [],
})
export class AppModule {}
